#pragma once


class FileOperator
{
public:
	FileOperator();
	~FileOperator();
public:
	int OpenFile(LPCTSTR pszFilename, char*& pStart, char*& pEnd);
	int CloseFile();
	int AppendFile(LPCTSTR pszHeadFilename,LPCTSTR pszTailFilename);
protected:
	wchar_t* m_strFilename;
	HANDLE m_hFile;
	HANDLE m_hFileMap;
	char* m_pFileStart;
private:
};

/************************************************************************/
/* command-line parser                                                  */
/************************************************************************/
class cmdline
{
public:
	cmdline();
	~cmdline(){};
	enum{OP_NONE, OP_HELP, OP_PARSE_FILE, OP_PARSE_FILE_WITHDEVID, OP_MERGE_FILES};

public:
	int GetOPType(){return optype_;};
	std::string GetParseFile(){return parsefilename_;};
	std::vector<unsigned int> GetParseFile_devids(){return parsefiledevids_;};
	std::string GetMergeSrcFiles(){return mergefilesrcnames_;};
	std::string GetMergeDstFile(){return mergefiledstname_;};

	int ParseCmdLine(int argc, _TCHAR* argv[]);
protected:
	int ParseDevid(const std::string&);
protected:
	int optype_;
	std::string parsefilename_;
	std::vector<unsigned int> parsefiledevids_;
	std::string mergefilesrcnames_;
	std::string mergefiledstname_;

private:
};

/************************************************************************/
/* Global functions                                                     */
/************************************************************************/
int OutPutHelpTxt();
int ParseFile(const std::string& filename, const condition* = NULL );
int MergeFiles(const std::string& pszSourceFiless, const std::string& pszDstFile);

int ConstructParser(ParserBase*&);

#define VIWRITE_TYPE_5 5
#define VIWRITE_TYPE_6 6
#define VIREAD_TYPE_4 4
#define VIREAD_TYPE_5 5

int CreateviwrtParser(FuncParser*&, int nType);
int CreatevirdParser(FuncParser*&,int nType);
int CreateviGeneralParser(GeneralFunc_Parser*&);

int CreateibwrtParser(FuncParser*&);
int CreateibrdParser(FuncParser*&);
int CreateibGeneralParser(GeneralFunc_Parser*&);

int CreateNestedFuncParser(NestedFuncParser*&);

